<?php
/**
 * Formular domeny
 * @author Tomas Srna
 * @package bakalarka
 */

class DomainForm extends Form 
{
	public function __construct(Template $template, $values = NULL, 
		$action = NULL, $method = 'POST')
	{
		parent::__construct($template, $values, $action, $method);
		
		// name, label, [type], [class], [hint], [$options]
		$this->items = array(
			new Element('name', L::selected()->name, "text", 
						"required nospace"),
			new Element('active', L::selected()->active, "select", 
						"required", "", array(1 => L::selected()->yes,
							0 => L::selected()->no)),
		);
	}
	
	/**
	 * Pokial nam zakladne kontroly nestacia, mozme si pridat vlastne
	 * specificke pre dany formular
	 */
	public function validate()
	{
		parent::validate();
		
		if(!$this->getError('name') &&
			!preg_match('/^[a-z0-9\\.-]+$/i', 
				$this->getValue('name')))
		{
			$this->setError('name', 
				sprintf(L::selected()->invalidFormat_s, 
					'a-z, A-Z, 0-9, . -'));
		}
		
		if(count($this->errors) > 0)
			return false;
		
		return true;
	}
}
